package com.ethan.lotgateway.netty.handler;

import com.ethan.lotgateway.DataInfo;
import com.ethan.lotgateway.netty.config.MqSender;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@ChannelHandler.Sharable
public class MqHandler extends ChannelInboundHandlerAdapter {
    @Autowired
    MqSender mqSender;
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        System.out.println("-----mqhandler");
        if (msg instanceof DataInfo){
            DataInfo dataInfo = (DataInfo) msg;
            mqSender.sendMsg("lot.data.test",dataInfo.getData());
        }
    }
}
